/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { FileSet } from '@ohos/hvigor';
import * as fse from 'fs-extra';

import { CodeType } from '../../enum/code-type-enum.js';

import { TaskNames } from '../common/task-names.js';
import { TargetTaskService } from '../service/target-task-service.js';
import { CompileNode } from '../compile-node.js';
import Task = TaskNames.Task;

/**
 * 处理ohosTest Target时调用loader编译新模型的js/arkts源码
 *
 * @since 2022/12/22
 */
export class OhosTestCompileNode extends CompileNode {
  constructor(taskService: TargetTaskService, codeType: CodeType) {
    super(taskService, codeType, Task.OHOS_TEST_COMPILE_NODE);
  }

  declareInputFiles(): FileSet {
    const fileSet = super.declareInputFiles();

    // ohosTest引用了main中的代码时，main源码也要作为编译增量条件
    if (this.mainCodePath && fse.existsSync(this.mainCodePath!)) {
      fileSet.addEntry(this.mainCodePath!, { isDirectory: true });
    }
    return fileSet;
  }
}
